package com.itheima.exer.exercise.ex0925;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.Scanner;

public class NweDate {
    public static void main(String[] args) {
        System.out.println("请输入您的出生日期:");
        String birthday = new Scanner(System.in).nextLine();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate now = LocalDate.now();
        //把现在的时间变成一个string类型的时间
        String format = now.format(dateTimeFormatter);
        //把出生日期转变为一个LocalDate对象;
        LocalDate parse = LocalDate.parse(birthday, dateTimeFormatter);
        //计算两个时间之间的时间间隔;
        long days = Period.between(parse, now).toTotalMonths();
        System.out.println("您从"+birthday+"到"+format+"活了"+days+"月");
    }
}
